package com.itrip.itripsearch;

import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServer;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.apache.solr.client.solrj.response.QueryResponse;
import org.apache.solr.common.SolrDocument;
import org.apache.solr.common.SolrDocumentList;
import org.apache.solr.common.params.SolrParams;
import org.junit.jupiter.api.Test;

import java.util.List;

/**
 * 测试solr
 */
public class TextSolr {

     public static SolrServer solrServer = new HttpSolrServer(
             "http://localhost:8080/solr/hotel");

     @Test
     public void testQuery() throws SolrServerException {
         //查询得参数
         SolrQuery solrQuery = new SolrQuery();
         solrQuery.setQuery("*:*");

         //执行查询返回 response对象
         QueryResponse response = solrServer.query(solrQuery);
         int status =  response.getStatus();
         //查询状态
         System.out.println("status:"+ status);
         //QTime 查询毫秒级别
         int qTime = response.getQTime();
         System.out.println("qTime:"+qTime);

         SolrDocumentList results = response.getResults();
         //总数量
         long unmFound = results.getNumFound();
         System.out.println("unmFound:"+unmFound);
         //起始位置
         long start = results.getStart();
         System.out.println("start:"+start);

         List<ItripHotelVO> hotelList = response.getBeans(ItripHotelVO.class);
         for (ItripHotelVO hotelvo : hotelList){
             System.out.println(hotelvo);
         }

     }


}
